#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <set>

using namespace std;

class Solution {
public:
    vector<vector<int>> fourSum(vector<int>& nums, int target) {
        sort(nums.begin(), nums.end());

        vector<vector<int>> vv;
        int a = 0;
        int n = nums.size();

        while (a < n)
        {
            int b = a + 1;
            while (b < n)
            {
                long long key = (long long)target - nums[a] - nums[b];

                int left = b + 1, right = n - 1;
                while (left < right)
                {
                    if (nums[left] + nums[right] > key)  right--;
                    else if (nums[left] + nums[right] < key) left++;
                    else
                    {
                        vv.push_back({ nums[a] , nums[b] , nums[left] ,nums[right] });
                        left++;
                        right--;
                        while (left < right && nums[left] == nums[left - 1])   left++;
                        while (left < right && nums[right] == nums[right + 1])   right--;
                    }
                }

                b++;
                while (b < n && nums[b] == nums[b - 1]) b++;
            }

            a++;
            while (a < n && nums[a] == nums[a - 1]) a++;
        }

        return vv;
    }
};

int main()
{


	return 0;
}